﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MethodWorx.Core.DomainModel
{

    /// <summary>
    /// An IRepository contains the methods required to load and persist aggregate roots only
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public interface IRepository<T> : IRepository
        where T : AggregateRoot
    {
        /// <summary>
        /// Return all the entities by its ID
        /// </summary>
        /// <returns></returns>
        IEnumerable<T> All();

        IQueryable<T> Query();

        /// <summary>
        /// Indexer to retreive the repository from the data model
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        T this[Guid id] { get; }

        /// <summary>
        /// Create a new entity instance
        /// </summary>
        /// <returns></returns>
        T CreateEntityInstance();

        /// <summary>
        /// Returns a boolean indicating if the repository contains
        /// the entity
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        bool Contains(T entity);

        /// <summary>
        /// Insert the entity
        /// </summary>
        /// <param name="entity"></param>
        void Insert(T entity);

        /// <summary>
        /// Delete the entity
        /// </summary>
        /// <param name="entity"></param>
        void Delete(T entity);

        /// <summary>
        /// Update the entity
        /// </summary>
        /// <param name="entity"></param>
        void Update(T entity);
    }

    public interface IRepository
    {
        void Insert(object entity);
        void Delete(object entity);
        void Update(object entity);
        object CreateInstance(Type type);
    }

}
